package com.wxzz.elearing.user.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.EnterpriseIdentityDto;
import com.wxzz.elearing.user.dto.EnterpriseOrganizationDto;
import com.wxzz.elearing.user.entity.AdminUser;
import com.wxzz.elearing.user.entity.EnterpriseIdentity;
import com.wxzz.elearing.user.entity.EnterpriseOrganization;
import com.wxzz.elearing.user.service.IEnterpriseOrganizationService;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wx-enterprise-organization")
@Api(tags = "组织架构(小程序)")
public class WxEnterpriseOrganizationController {

    @Autowired
    private IEnterpriseOrganizationService enterpriseOrganizationService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;


    @ApiOperation(value = "根据pid展示组织架构(小程序)", notes = "根据pid展示组织架构(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listEnterpriseOrganizationByPid", method = RequestMethod.POST)
    public ReturnVO<List<EnterpriseOrganization>> listEnterpriseOrganizationByPid(@RequestHeader String token, @RequestBody EnterpriseOrganizationDto enterpriseOrganizationDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return enterpriseOrganizationService.listEnterpriseOrganizationByPid(jsonObject.getLong("enterpriseId"),enterpriseOrganizationDto);
    }

}
